package com.aqielife.aqiemusic.utils;

import com.aqielife.aqiemusic.model.user.User;

/**
 * @description 单例管理登陆用户信息
 */
public class UserManager {

    private static UserManager userManager = null;
    private User user = null;

    public static UserManager getInstance() {

        if (userManager == null) {

            synchronized (UserManager.class) {

                if (userManager == null) {

                    userManager = new UserManager();
                }
                return userManager;
            }
        } else {

            return userManager;
        }
    }

    /**
     * init the user 保存用户信息到内存
     */
    public void setUser(User user) {
        this.user = user;
        saveLocal(user);
    }

    // 保存用户信息到数据库
    private void saveLocal(User user) {

    }

    public boolean hasLogined() {
        return getUser() != null;
    }

    /**
     * has user info
     */
    public User getUser() {
        return this.user;
    }

    // 获取数据库中User
    private User getLocalUser(){
        return null;
    }
    /**
     * remove the user info
     */
    public void removeUser() {
        this.user = null;
        removeLocalUser();
    }

    // 清空数据库中用户信息
    private void removeLocalUser() {

    }
}

